from datetime import timedelta

from django.db.models import F
from django.utils import timezone

from polls.models import User
from vote2003 import app


@app.task
def check_inactive_user():
    time_before_30days = timezone.now() - timedelta(days=30)
    User.objects.filter(last_visit__lt=time_before_30days) \
        .filter(is_active=True).update(is_active=False)


@app.task
def update_user_votecount():

    User.objects.filter(is_active=True).update(vote_count=5)
    # .update(vote_count=F('vote_count') + 5)
